package graphics.object;

import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glColor3f;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glVertex2i;

import graphics.TestingGraphics;
import graphics.GLObjectManager.RenderPriority;
import graphics.object.interfaces.GLRenderableObject;

import java.awt.Rectangle;

public class GLRectangle extends Rectangle implements GLRenderableObject{
	
	private static final long serialVersionUID = 1L;
	private RenderPriority priority = RenderPriority.NORMAL;
	
	public GLRectangle(int x, int y, int width, int height){
		super(x, y, width, height);
	}
	
	public void onRender(){
	    glDisable(GL_BLEND);
        glDisable(GL_TEXTURE_2D);
        
		glBegin(GL_QUADS);
		glColor3f(1f, 1f, 1f);
		glVertex2i(this.x, this.y);
        glVertex2i(this.x + width, this.y);
        glVertex2i(this.x + width, this.y + this.height);
        glVertex2i(this.x, this.y + this.height);
        glEnd();
        
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
	}

	public void setRenderPriority(RenderPriority priority) {
		this.priority = priority;
		if(TestingGraphics.objectManager.hasObject(this)){
			TestingGraphics.objectManager.removeObject(this);
			TestingGraphics.objectManager.addObject(this);
		}
	}

	public RenderPriority getRenderPriority() {
		return priority;
	}
}
